<script type="text/javascript">
  /* <![CDATA[ */
    function insertSpinningIconIntoEditResourceDiv() {
      applyEditResourceDivPadding();
      insertWaitingImg("edit_resource");
    }

    function clearEditResourceDiv() { 
      zeroEditResourceDivPadding(); 
      $('edit_resource').innerHTML = "";
    }

    function clearFlashInfo() { 
      $("flash_info").innerHTML = "";
    }

    function removeErrorExplanation() { 
      var errorExplanation = $("errorExplanation"); 

      if (errorExplanation) {
        errorExplanation.remove();
      }
    }

    function onAddFile() {
      insertSpinningIconIntoEditResourceDiv();
      removeErrorExplanation();
      clearFlashInfo();
    }

    function onAddLink() {
      insertSpinningIconIntoEditResourceDiv();
      removeErrorExplanation();
      clearFlashInfo();
    }

    function onEditResource() {
      insertSpinningIconIntoEditResourceDiv();
      clearFlashInfo();
      removeErrorExplanation();
    }

    function onCancelEditResource() {
      clearEditResourceDiv();
      clearFlashInfo();
      removeErrorExplanation();
    }

    function checkCategory() {
      var vSelect = $("category_id");
      var vNotSelected = (vSelect.selectedIndex == 0);

      if (vNotSelected) {
        alert("Please select category.");
      }
      
      return !vNotSelected;
    }

    function setEditResourceDivPadding(p_) {
      $("edit_resource").style.padding = p_;
    }

    function applyEditResourceDivPadding() {
      setEditResourceDivPadding("10px 0px");
    }

    function zeroEditResourceDivPadding() {
      setEditResourceDivPadding("0px 0px");
    }

    addToOnLoad(zeroEditResourceDivPadding) ;
  /* ]]> */
</script>
<% title = @ecase.title %>
<div class="resources" >
  <p class="sup_title" ><%= @ecase.country.name %> / <%= link_to title, 
    {:controller => "ecases", :action => :show, :id => @ecase.id} %></p>
  <h1 class="title" ><%= title %></h1>
  <div class="menu" >
    <% if can_add_resources? %>
    <div class="right" >
      <p>
        <%= link_to_remote "Add a file", {:update => "edit_resource", 
            :url => {:action => :add_file, :id => @ecase},
            :after => "onAddFile()"}, 
            :class => "red" %> | 
        <%= link_to_remote "Add a link", {:update => "edit_resource", 
            :url => {:action => :add_link, :id => @ecase},
            :after => "onAddLink()"}, 
            :class => "red" %>
      </p>
    </div>
    <% end %>
    <div class="left" >Project Resources</div>
  </div>
  <div id="flash_info" ><%= flash_info_tag %></div>
  <div id="edit_resource" >
    <%= render :partial => "edit_file" if @show_edit_file %>
  </div>
  <%= error_messages_for :error_resource %>
  <%= render :partial => "resources_table", 
    :locals => {:id => "documents", :title => "Papers", :partial => "document", :collection => @documents} %>
  <%= render :partial => "resources_table", 
    :locals => {:id => "videos", :title => "Video", :partial => "video", :collection => @videos} %>
  <%= render :partial => "resources_table", 
    :locals => {:id => "images", :title => "Images", :partial => "image", :collection => @images} %>
  <%= render :partial => "resources_table", 
    :locals => {:id => "links", :title => "Links", :partial => "link", :collection => @links} %>
</div>